home *** CD-ROM | disk | FTP | other *** search
/ User's Choice Windows CD / User's Choice Windows CD (CMS Software)(1993).iso / utility1 / gs261src.zip / OPDEF.H < prev    next >
C/C++ Source or Header  |  1993-05-13  |  4KB  |  92 lines

  1. /* Copyright (C) 1991, 1992 Aladdin Enterprises.  All rights reserved.
  2.  
  3. This file is part of Ghostscript.
  4.  
  5. Ghostscript is distributed in the hope that it will be useful, but
  6. WITHOUT ANY WARRANTY.  No author or distributor accepts responsibility
  7. to anyone for the consequences of using it or for whether it serves any
  8. particular purpose or works at all, unless he says so in writing.  Refer
  9. to the Ghostscript General Public License for full details.
  10.  
  11. Everyone is granted permission to copy, modify and redistribute
  12. Ghostscript, but only under the conditions described in the Ghostscript
  13. General Public License.  A copy of this license is supposed to have been
  14. given to you along with Ghostscript so you can know your rights and
  15. responsibilities.  It should be in a file named COPYING.  Among other
  16. things, the copyright notice and this notice must be preserved on all
  17. copies.  */
  18.  
  19. /* opdef.h */
  20. /* Operator definition interface for Ghostscript */
  21.  
  22. /* Typedef for an operator procedure. */
  23. /*
  24.  * Operator procedures return 0 for success, a negative code for an error, 
  25.  * or a positive code for some uncommon situations (see below).
  26.  */
  27. typedef int (*op_proc_p)(P1(os_ptr));
  28.  
  29. /* Structure for initializing the operator table. */
  30. /*
  31.  * Each operator file declares an array of these, of the following kind:
  32.  
  33. op_def my_defs[] = {
  34.     {"1name", zname},
  35.         ...
  36.     op_def_end(iproc)
  37. }
  38.  
  39.  * where iproc is an initialization procedure for the file, or 0.
  40.  * This definition always appears at the END of the file,
  41.  * to avoid the need for forward declarations for all the
  42.  * operator procedures.
  43.  *
  44.  * Internal operators whose names begin with %, such as continuation
  45.  * operators, do not appear in systemdict.  Ghostscript assumes
  46.  * that these operators cannot appear anywhere (in executable form)
  47.  * except on the e-stack; to maintain this invariant, the execstack
  48.  * operator converts them to literal form, and cvx refuses to convert
  49.  * them back.  As a result of this invariant, they do not need to
  50.  * push themselves back on the e-stack when executed, since the only
  51.  * place they could have come from was the e-stack.
  52.  */
  53. typedef struct {
  54.     const char _ds *oname;
  55.     op_proc_p proc;
  56. } op_def;
  57. typedef const op_def _ds *op_def_ptr;
  58. #define op_def_end(iproc) {(char _ds *)0, (op_proc_p)iproc}
  59.  
  60. /*
  61.  * All operators are catalogued in a table, primarily so
  62.  * that they can have a convenient packed representation.
  63.  * The `size' of an operator is normally its index in this table;
  64.  * however, internal operators have a `size' of 0, and their true index
  65.  * must be found by searching the table for their procedure address.
  66.  */
  67. extern ushort op_find_index(P1(const ref *));
  68. #define op_index(opref)\
  69.   (r_size(opref) == 0 ? op_find_index(opref) : r_size(opref))
  70. /*
  71.  * There are actually two kinds of operators: the real ones (t_operator),
  72.  * and ones defined by procedures (t_oparray).  The catalog for the former
  73.  * is op_def_table, and their index is in the range [1..op_def_count).
  74.  */
  75. /* Because of a bug in Sun's SC1.0 compiler, */
  76. /* we have to spell out the typedef for op_def_ptr here: */
  77. extern const op_def _ds **op_def_table;
  78. extern uint op_def_count;
  79. #define op_num_args(opref) (op_def_table[op_index(opref)]->oname[0] - '0')
  80. /*
  81.  * The catalog for the latter is op_array_table, and their index is in
  82.  * the range [op_def_count..op_def_count+op_array_count).  The actual
  83.  * index in op_array_table is the operator index minus op_def_count.
  84.  */
  85. extern ref op_array_table;        /* t_array */
  86. extern ushort *op_array_nx_table;
  87. extern uint op_array_count;
  88. #define op_index_ref(index,pref)\
  89.   ((index) < op_def_count ?\
  90.    make_oper(pref, index, op_def_table[index]->proc) :\
  91.    (r_set_type_attrs(pref, t_oparray, a_executable), r_set_size(pref, index)))
  92.